package com.cskaoyan.controller;

import com.cskaoyan.bo.wxorder.CommentBo;
import com.cskaoyan.bo.wxorder.OrderSubmitBo;
import com.cskaoyan.service.wxorder.WxOrderService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.wxorder.OrderCommentInfoVo;
import com.cskaoyan.vo.wxorder.OrderDetailVo;
import com.cskaoyan.vo.wxorder.OrderIdVo;
import com.cskaoyan.vo.wxorder.OrderListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class WxOrderController {

    @Autowired
    WxOrderService wxOrderService;

    @RequestMapping("wx/order/submit")
    public BaseRespVo orderSubmit(@RequestBody OrderSubmitBo orderSubmitBo) {
        int orderId = wxOrderService.submitOrder(orderSubmitBo);
        if (orderId == -1) {
            return BaseRespVo.error(200, "库存不足");
        }
        return BaseRespVo.ok(new OrderIdVo(orderId));
    }

    @RequestMapping("wx/order/prepay")
    public BaseRespVo orderPrepay(@RequestBody OrderIdVo orderIdBo) {

        return BaseRespVo.error(724, "不能支付哦~");
    }

    @RequestMapping("wx/order/list")
    public BaseRespVo orderList(Integer showType, Integer page, Integer size) {
        OrderListVo orderListVo = wxOrderService.listOrder(showType, page, size);
        return BaseRespVo.ok(orderListVo);
    }

    @RequestMapping("wx/order/detail")
    public BaseRespVo orderDetail(Integer orderId) {
        OrderDetailVo orderDetailVo = wxOrderService.selectOrderDetail(orderId);
        return BaseRespVo.ok(orderDetailVo);
    }

    @RequestMapping("wx/order/cancel")
    public BaseRespVo orderCancel(@RequestBody OrderIdVo orderIdBo) {
        wxOrderService.cancelOrder(orderIdBo.getOrderId());
        return BaseRespVo.ok();
    }

    @RequestMapping("wx/order/refund")
    public BaseRespVo orderRefund(@RequestBody OrderIdVo orderIdBo) {
        wxOrderService.refund(orderIdBo.getOrderId());
        return BaseRespVo.ok();
    }

    @RequestMapping("wx/order/delete")
    public BaseRespVo orderDelete(@RequestBody OrderIdVo orderIdBo) {
        wxOrderService.deleteOrder(orderIdBo.getOrderId());
        return BaseRespVo.ok();
    }

    @RequestMapping("wx/order/confirm")
    public BaseRespVo orderConfirm(@RequestBody OrderIdVo orderIdBo) {
        wxOrderService.confirmOrder(orderIdBo.getOrderId());
        return BaseRespVo.ok();
    }

    // http://182.92.235.201:8083/wx/order/goods?orderId=30&goodsId=1152031
    @RequestMapping("wx/order/goods")
    public BaseRespVo orderGoods(Integer orderId, Integer goodsId) {
        OrderCommentInfoVo orderCommentInfoVo = wxOrderService.goodCommentInfo(orderId, goodsId);
        return BaseRespVo.ok(orderCommentInfoVo);
    }

    @RequestMapping("wx/order/comment")
    public BaseRespVo orderComment(@RequestBody CommentBo commentBo) {
        wxOrderService.comment(commentBo);
        return BaseRespVo.ok();
    }

}
